package utils;

import com.kennycason.kumo.image.AngleGenerator;

import java.util.Random;

public class MyAngleGenerator extends AngleGenerator {

    private static final Random RANDOM = new Random();
    private final int steps;
    private final double[] thetas;
    private int next;

    public MyAngleGenerator() {
        this.steps = 3;
        this.thetas = this.calculateThetas(-90.0D, 90.0D);
    }

    @Override
    public double randomNext() {
        // 0.8 水平 0.2 垂直
        int i = RANDOM.nextInt(10);
        if (i < 2) { // 这里修改概率
            i = RANDOM.nextInt(2);
            if (i < 1) {
                return thetas[0];
            } else {
                return thetas[2];
            }
        } else {
            return this.thetas[1];
        }
    }

    private double[] calculateThetas(double to, double from) {
        double stepSize = (to - from) / (double)(this.steps - 1);
        double[] thetas = new double[this.steps];

        for(int i = 0; i < this.steps; ++i) {
            thetas[i] = this.degreesToRadians(from + (double)i * stepSize);
        }

        return thetas;
    }

    private double degreesToRadians(double degrees) {
        return 3.141592653589793D * degrees / 180.0D;
    }

}
